<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    //
    const DISPLAY = 1;
    const HIDDEN = 2;

    public function getStatusList(){
        return [
            self::DISPLAY =>  '展示',
            self::HIDDEN    =>  '隐藏'
        ];
    }
    public function getStatusString($status){
        return ($this->getStatusList())[$status];
    }

    public function children(){
        return $this->hasMany('App\Category','pid')->with('children');
    }
    public static function getSon($pid,$bool=false){
        if($bool){
            return self::where('pid',$pid)->where('status',self::DISPLAY)->get();
        }
        return self::where('pid',$pid)->get();
    }
        //写操作

}
